function ajax (url){
  return new Promise(function(resolve, reject){
    var xhr = new XMLHttpRequest()
    xhr.open('GET', url)
    xhr.responseType = 'json'
    xhr.onload = function() { // 请求完成后
      if (this.status === 200) {
        resolve(this.response)
      }else{
        reject(new Error(this.statusText))
      }
    }
    xhr.send() // 开始执行
  })
}

async function main (){
  try {
    const users = await ajax('./api/users.json')
    console.log(users)

    const users2 = await ajax('./api/users.json')
    console.log(users2)
  } catch (e){
    console.log(e)
  }
}

const promise = main()
promise.then(()=>{
  console.log('all commpleted')
})